package com.example.androidmvp;

import java.util.List;

import android.content.Context;

/**
 * Created by kerray on 2016/9/25.
 */

public class ContactsPresenterImpl implements ContactsPresenter, onContactsListener {
    private ContactsView mView;
    private ContactsModel mModel;

    public ContactsPresenterImpl(ContactsView pContactsView) {
        mView = pContactsView;
        mModel = new ContactsModelImpl();
    }

    @Override
    public void getContacts(int num, Context pContext) {
        if (mView != null)
            mView.showProgress();

        mModel.getContacts(num, this, pContext);
    }

    @Override
    public void onDestroy() {
        mView = null;
    }

    @Override
    public void onNullError() {
        if (mView != null) {
            mView.setNullError();
            mView.hideProgress();
        }
    }

    @Override
    public void onNotError() {
        if (mView != null) {
            mView.setNotError();
            mView.hideProgress();
        }
    }

    @Override
    public void onSuccess() {
        if (mView != null) {
            mView.navigateToHome();
            mView.hideProgress();
        }
    }

    @Override
    public void onGetContactsSuccess(List<SortModel> model) {
        mView.getContactsSuccess(model);
        mView.hideProgress();
    }
}
